#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    int cnt = 5;
    while(cnt--)
    {
      printf("I am a child process,pid:%d\n",getpid());
      sleep(1);
    }
    exit(1);
  }

  else if(id > 0)
  {
    sleep(10);
    int status = 0;
    
    pid_t rid = waitpid(id, &status, 0);
    if(rid == id)
    {
      int exit_code = ((status >> 8) & 0xFF);
      int exit_sig = status & 0x7F;
    
      printf("pid:%d,wait success!status:%d,status_code:%d,exit_sig:%d\n",getpid(),status,exit_code,exit_sig);
    }
    sleep(5);
  }

  return 0;
}
